//
//  THApplyToBeBabyTeacherViewController.m
//  TreeHole
//
//  Created by apple on 2020/9/21.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THApplyNewBabyInfoViewController.h"
#import "STTools_TextView.h"
#import "STTools_RadioButton.h"
#import "SMAddressChosedViewController.h"
@interface THApplyNewBabyInfoViewController ()

@property(nonatomic, strong) NSMutableArray<NSArray*>                     *dataSouce;/**<  */
@property(nonatomic, strong) UITextField                     *nameTextFiled;/**<  */
@property(nonatomic, strong) NSMutableArray<STButton*>                     *buttonArray;/**<  */
@property(nonatomic, strong) STTools_TextView                     *text_view;/**<  */
@property(nonatomic, strong) STTools_ImageAutoChoseView                     *autoView;/**<  */

@property(nonatomic, strong) NSString                     *icon_url;/**<  */
@property(nonatomic, strong) NSString                     *service_area;/**<  */
@property(nonatomic, strong) NSString                     *sex;/**<  */

@property(nonatomic, strong) YYLabel                      *chatLable;/**< u */
@property(nonatomic, strong) UIView                       *contentView;/**<  */
@property(nonatomic, strong) STButton                     *agreeButton;/**<  */
@end

@implementation THApplyNewBabyInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我是育婴师";
    self.tableView.frame = CGRectMake(0, TMUtils.stoneobs_fun_get_navgationBarBootom , UISCREEN_WIDTH, TMUtils.stoneobs_fun_get_tabBarTop-TMUtils.stoneobs_fun_get_navgationBarBootom - 44);
    self.tableView.contentInset = UIEdgeInsetsZero;
    [self stoneobs_ui_configSubView];
    [self config_dataSouce];
    [self config_tableFooter];
    [self stoneobs_fun_st_autoAdjustAllResponder];
    
    __weak typeof(self) weakSelf =  self;

    
    STButton * button = [[STButton alloc] initWithFrame:CGRectMake(20, TMUtils.stoneobs_fun_get_tabBarTop, UISCREEN_WIDTH - 40, 44)
                                                  title:@"提交认证"
                                             titleColor:UIColor.whiteColor
                                              titleFont:15
                                           cornerRadius:22
                                        backgroundColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR
                                        backgroundImage:nil
                                                  image:nil];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    button.centerX = self.tableView.width / 2;
    [self.view addSubview:button];
    [button setClicAction:^(UIButton *sender) {
        [weakSelf onSelctedCommitButton];
    }];
    button.titleLabel.font = [UIFont fontWithName:STONEOBS_UI_FONT_CU_NAME size:15];
    // Do any additional setup after loading the view.
}
#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    UIView * header = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    header.backgroundColor = UIColor.whiteColor;
    __weak typeof(self) weakSelf =  self;
    CGFloat top = 0;
    ({
        UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, UISCREEN_WIDTH, 10)];
        stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
        [header addSubview:stoneobs_ui_line];
        top = stoneobs_ui_line.bottom + 20;
    });
    
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, top, 60, 60)
                                                                  title:nil
                                                             titleColor:nil
                                                              titleFont:30
                                                           cornerRadius:30
                                                        backgroundColor:nil
                                                        backgroundImage:ST_IMAGE_NAMED(@"头像女孩")
                                                                  image:nil];
        [header addSubview:stoneobs_ui_button];
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [weakSelf stoneobs_fun_st_showchosePhotoImagePicker:^(UIImage *image) {
                //上传图片
                [TMQNUploadManger.manger sendQiNiuWithImage:image handle:^(NSString * _Nonnull url) {
                    if (url.length) {
                        weakSelf.icon_url = url;
                        [sender setBackgroundImage:image forState:UIControlStateNormal];
                    }
                    
                }];
            }];
        }];
        stoneobs_ui_button.centerX = UISCREEN_WIDTH / 2;
        top = stoneobs_ui_button.bottom + 10;
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(0, top, UISCREEN_WIDTH, 20)
                                                                text:@"点击上传头像"
                                                           textColor:STONEOBS_UI_SECEND_TEXT_COLOR
                                                                font:13
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentCenter];
        [header addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom + 30;
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, UISCREEN_WIDTH, 20)
                                                                text:@"姓名"
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:13
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [header addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom;
        
        UITextField * textFiled = [self textFiledFromPlaceHolder:@"请填写真实姓名"];
        textFiled.width = UISCREEN_WIDTH - 30;
        textFiled.top = top;
        textFiled.left = 15;
        textFiled.height = 40;
        textFiled.textAlignment = NSTextAlignmentLeft;
        [textFiled stoneobs_fun_st_showBottomLine];
        [header addSubview:textFiled];
        self.nameTextFiled = textFiled;
        top = textFiled.bottom + 15;
    });
    
    header.height = top;
    self.tableView.tableHeaderView = header;
}
- (void)config_dataSouce{
    self.dataSouce = NSMutableArray.new;

    ({
       NSArray * array = @[
           [[STTools_TableEasyModel alloc] initWithTextString:@"性别" detailString:@"请填写性别"],
           [[STTools_TableEasyModel alloc] initWithTextString:@"年龄" accessoryView:[self textFiledFromPlaceHolder:@"请填写年龄"]],
            [[STTools_TableEasyModel alloc] initWithTextString:@"职业年龄" accessoryView:[self textFiledFromPlaceHolder:@"请填写职业年龄"]],
            [[STTools_TableEasyModel alloc] initWithTextString:@"身份证号" accessoryView:[self textFiledFromPlaceHolder:@"请填写身份证号"]],
           [[STTools_TableEasyModel alloc] initWithTextString:@"请填写服务区域" detailString:@"请选择服务区域"],

       ];
        [self.dataSouce addObject:array];
    });
    
    [self.tableView reloadData];
}
- (UITextField*)textFiledFromPlaceHolder:(NSString*)placeholder{
    UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH*0.6, 50)];
    textFiled.textAlignment = NSTextAlignmentRight;
    textFiled.placeholder = placeholder;
    textFiled.font = [UIFont systemFontOfSize:13];
    textFiled.textColor = WH_UICOLOR_FROM_RGBA(0x999999);
//    if (self.apply_model) {
//        if ([placeholder containsString:@"性别"]) {
//            textFiled.text = self.apply_model.cus_sex;
//        }
//        if ([placeholder containsString:@"请填写年龄"]) {
//            textFiled.text = self.apply_model.age;
//        }
//        if ([placeholder containsString:@"请填写职业年龄"]) {
//            textFiled.text = self.apply_model.job_age;
//        }
//        if ([placeholder containsString:@"请填写身份证号"]) {
//            textFiled.text = self.apply_model.card;
//        }
//    }
    return textFiled;
}
- (void)config_tableFooter{
    
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, TMUtils.stoneobs_fun_get_tabBarTop-44, STONEOBS_UI_UISCREEN_WIDTH, 49)];
    self.contentView = view;
    [self.view addSubview:view];
    
    ({
        STButton * cbutton = [[STButton alloc] initWithFrame:CGRectMake(15, 0, 20, 20)
                                                       title:@""
                                                  titleColor:UIColor.whiteColor
                                                   titleFont:15
                                                cornerRadius:0
                                             backgroundColor:nil
                                             backgroundImage:[UIImage imageNamed:@"tyi_wxz"]
                                                       image:nil];
        cbutton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [cbutton setBackgroundImage:[UIImage imageNamed:@"tyi"] forState:UIControlStateSelected];
        [cbutton setClicAction:^(UIButton *sender) {
            sender.selected = !sender.selected ;
        }];
        cbutton.centerY = 24.5;
        self.agreeButton = cbutton;
        cbutton.selected = YES;
        
        self.chatLable = [YYLabel new];
        self.chatLable.numberOfLines = 0;
        [view addSubview:self.chatLable];
        self.chatLable.layer.cornerRadius = 4;
        self.chatLable.clipsToBounds = YES;
        self.chatLable.displaysAsynchronously=YES;
        self.chatLable.userInteractionEnabled = YES;
        
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            NSMutableAttributedString  *resultAttr = [[NSMutableAttributedString alloc] initWithString:@""];
            resultAttr.alignment = NSTextAlignmentLeft;
            resultAttr.lineSpacing = 3;
            ({
                NSMutableAttributedString *headerText = [[NSMutableAttributedString alloc] initWithString:@"同意并接受"];
                [headerText setColor:STONEOBS_UI_FIRST_TEXT_COLOR range:headerText.rangeOfAll];
                headerText.font = [UIFont systemFontOfSize:15];
                [resultAttr appendAttributedString:headerText];
            });
            ({
                NSString * title = @"《育婴师协议》";
                NSMutableAttributedString *headerText = [[NSMutableAttributedString alloc] initWithString:title];
                [headerText setColor:STONEOBS_UI_THEME_BACKGROUNDCOLOR range:headerText.rangeOfAll];
                headerText.font = [UIFont systemFontOfSize:15];
                [resultAttr appendAttributedString:headerText];
                
                ({
                    YYTextHighlight *highlight = [YYTextHighlight new];
                    [highlight setColor:[UIColor whiteColor]];
                    highlight.tapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
                        
                        
                        DDLogInfo(@"用户协议》");
                        [BFBaseConfigDataController stoneobs_fun_get_keyword:@"yysxieyi" handle:^(NSString * _Nonnull h5String) {
                            STTools_WebViewController * webVc = [[STTools_WebViewController alloc] initWithH5String:h5String];
                            webVc.forceTitle = @"育婴师协议";
                            [self pushViewController:webVc animated:1];
                        }];
                    };
                    NSString * nameTitle = resultAttr.string;
                    NSRange range = [nameTitle rangeOfString:title];
                    [resultAttr setTextHighlight:highlight range:range];
                });
            });

            
            YYTextContainer *titleContarer = [YYTextContainer new];
            titleContarer.size = CGSizeMake(CGFLOAT_MAX,49);
            
            YYTextLayout *titleLayout = [YYTextLayout layoutWithContainer:titleContarer text:resultAttr];
            CGFloat titleLabelWith= titleLayout.textBoundingSize.width;
            
            dispatch_async(dispatch_get_main_queue(), ^{
                self.chatLable.textLayout = titleLayout;
                self.chatLable.frame = CGRectMake(cbutton.right+5, 0, titleLabelWith+10, 49);
                [view addSubview:cbutton];
                view.width = self.chatLable.right;
                view.centerX = STONEOBS_UI_UISCREEN_WIDTH / 2;
                
            });
        });
        
    });
    
    
    UIView * footer = [[UIView alloc] initWithFrame:STONEOBS_UI_UISCREEN_FRAME];
    footer.backgroundColor = UIColor.whiteColor;
    __weak typeof(self) weakSelf =  self;
    CGFloat top = 0;
    ({
        UIView * stoneobs_ui_line = [[UIView alloc] initWithFrame:CGRectMake(0, top, UISCREEN_WIDTH, 10)];
        stoneobs_ui_line.backgroundColor = self.tableView.backgroundColor;
        [footer addSubview:stoneobs_ui_line];
        top = stoneobs_ui_line.bottom + 20;
    });
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, UISCREEN_WIDTH, 20)
                                                                text:@"专业擅长"
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:13
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [footer addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom + 5;

    });
    
    ({
        if (self.buttonArray.count == 0) {
            NSArray * array = [self.apply_model.majorList stoneobs_fun_arrayFromObjKeyName:@"obj.name"];
            NSArray * id_array = [self.apply_model.majorList stoneobs_fun_arrayFromObjKeyName:@"obj.m_id"];
            self.buttonArray = NSMutableArray.new;
            CGFloat left = 15;
            CGFloat tempTop = top;
            NSInteger index = 0;
            for (NSString * name in array) {
                CGFloat witdh = [name stoneobs_fun_st_widthWithheight:12 font:12];
                UIImage * naimage = ST_IMAGE_NAMED(@"wxzzf");
                UIImage * simage = ST_IMAGE_NAMED(@"xzzhifu");
                witdh = witdh + naimage.size.width + 10;
                if (witdh > UISCREEN_WIDTH - 80) {
                    witdh = UISCREEN_WIDTH - 80;
                }
                STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(left, tempTop, witdh, 35)
                                                                          title:name
                                                                     titleColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                      titleFont:12
                                                                   cornerRadius:0
                                                                backgroundColor:nil
                                                                backgroundImage:nil
                                                                          image:naimage];
                [stoneobs_ui_button setImage:simage forState:UIControlStateSelected];
                [footer addSubview:stoneobs_ui_button];
                [stoneobs_ui_button setClicAction:^(UIButton *sender) {
                    sender.selected = !sender.selected;
                }];
                stoneobs_ui_button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
                [self.buttonArray addObject:stoneobs_ui_button];
                tempTop = stoneobs_ui_button.bottom;
                stoneobs_ui_button.obj_id = id_array[index];
                
                ({
                    UITextField * textFiled = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 60, 35)];
                    textFiled.font = [UIFont systemFontOfSize:10];
                    [footer addSubview:textFiled];
                    stoneobs_ui_button.textFiled = textFiled;
                    textFiled.right = UISCREEN_WIDTH  - 15;
                    textFiled.centerY = stoneobs_ui_button.centerY;
                    textFiled.textAlignment = NSTextAlignmentRight;
                    [textFiled stoneobs_fun_st_showBottomLine];
                    textFiled.placeholder = @"请输入价格";
                    textFiled.keyboardType = UIKeyboardHIDUsageKeyboardPeriod;
                });
                index ++;
            }
            
            top = self.buttonArray.lastObject.bottom + 10;
        }else{
            for (STButton * button in self.buttonArray) {
                [footer addSubview:button];
                [footer addSubview:button.textFiled];
                top = button.bottom + 3;
            }
        }
        

    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, UISCREEN_WIDTH, 20)
                                                                text:@"个人简介"
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:13
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [footer addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom +8;

    });
    
    ({
        if (!self.text_view) {
            self.text_view = [[STTools_TextView alloc] initWithFrame:CGRectMake(15, top, footer.width - 30, 100)];
            self.text_view.placeholder = @"请填写个人简介";
            self.text_view.label.left = 15;
            self.text_view.label.top = 5;
            self.text_view.layer.cornerRadius = 8;
            self.text_view.clipsToBounds = YES;
            self.text_view.backgroundColor = WH_UICOLOR_FROM_RGBA(0xEEEEEE);
        }
        top = self.text_view.bottom+5;
        [footer addSubview:self.text_view];
        
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(15, top, UISCREEN_WIDTH, 20)
                                                                text:[NSString stringWithFormat:@"资格证书(%ld/5)",self.autoView.stoneobs_fun_get_allImages.count]
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:13
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        [footer addSubview:stoneobs_ui_label];
        top = stoneobs_ui_label.bottom+8 ;

    });
    
    ({
        if (!self.autoView) {
            __weak typeof(self) weakSelf =  self;
            self.autoView = [[STTools_ImageAutoChoseView alloc] initWithFrame:CGRectMake(15,top, footer.width - 30, 100)];
            [self.autoView setFrameDidChangedHandle:^(STTools_ImageAutoChoseView *autochoseView) {
                [weakSelf config_tableFooter];
            }];
        }
        [footer addSubview:self.autoView];
        top = self.autoView.bottom + 20;
    });
    footer.height = top;
    self.tableView.tableFooterView = footer;
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSouce[section].count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 20;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
        
    }
    STTools_TableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:model];
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTools_TableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    if ([model.textString containsString:@"服务区域"]) {
        SMAddressChosedViewController * vc = SMAddressChosedViewController.new;
        [vc setOnSlectedhandle:^(NSArray * _Nonnull codeArray, NSArray * _Nonnull placeArray) {
            model.detailString = [placeArray componentsJoinedByString:@""];
            self.service_area = model.detailString;
            [self.tableView reloadData];
        }];
        [self presentViewController:vc animated:NO completion:nil];
    }
    if ([model.textString isEqualToString:@"性别"]) {
        NSArray * array = @[@"男",@"女",@"取消"];
        [self stoneobs_fun_st_showActionSheet:array andWithBlock:^(int tag) {
            if (tag < 2) {
                model.detailString = array[tag];
                self.sex = @(tag+1).description;
                [self.tableView reloadData];
                
            }
        }];
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
- (STTools_TableEasyModel*)modelFormText:(NSString*)text{
    for (STTools_TableEasyModel * model in self.dataSouce.stoneobs_fun_dissolveArray) {
        if ([model.textString containsString:text]) {
            return model;
        }
    }
    return nil;
}
#pragma mark --stoneobs Action Method
- (void)onSelctedCommitButton{
    if (!self.agreeButton.selected) {
        [SVProgressHUD showErrorWithStatus:@"请同意协议"];
        return;;
    }
    if (!self.icon_url.length) {
        [SVProgressHUD showInfoWithStatus:@"请选择头像"];
        return;
    }
    if (!self.nameTextFiled.text.length) {
        [SVProgressHUD showInfoWithStatus:@"请输入姓名"];
        return;
    }
    
    for (STTools_TableEasyModel * model in self.dataSouce.stoneobs_fun_dissolveArray) {
        if (model.accessoryView) {
            UITextField * textFiled = (id)model.accessoryView;
            if (!textFiled.text.length) {
                [SVProgressHUD showErrorWithStatus:textFiled.placeholder];
                return;
            }
        }
    }
    if (!self.service_area.length) {
        [SVProgressHUD showInfoWithStatus:@"请选择服务区域"];
        return;
    }
    
    NSMutableArray * major_ids = NSMutableArray.new;
    NSMutableArray * price_s= NSMutableArray.new;
    for (STButton * button in self.buttonArray) {
        if (button.selected) {
            [major_ids addObject:button.obj_id];
            if (button.textFiled.text.length) {
                [price_s addObject:button.textFiled.text];
            }else{
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"请输入专业的价格"]];
                return;;
            }
            
        }
    }
    if (!self.sex.length) {
        [SVProgressHUD showInfoWithStatus:@"请选择性别"];
        return;
    }
    if (!major_ids.count) {
        [SVProgressHUD showInfoWithStatus:@"请选择擅长专业"];
        return;
    }
    
    if (!self.text_view.text.length) {
        [SVProgressHUD showInfoWithStatus:@"请输入个人简介"];
        return;
    }
    
    if (self.autoView.stoneobs_fun_get_allImages.count == 0) {
        [SVProgressHUD showInfoWithStatus:@"请选择个人证书"];
        return;
    }else{
        NSArray * imag_array = self.autoView.stoneobs_fun_get_allImages;
        [TMQNUploadManger.manger uploadMoreImage:imag_array handle:^(BOOL success, NSArray * _Nonnull array) {
            if (array.count == imag_array.count) {
                [self send_add_apply_request_urls:array.mj_JSONString];
            }else{
               [SVProgressHUD showErrorWithStatus:@"上传失败请重试"];
            }
        }];
    }
}
- (void)send_add_apply_request_urls:(NSString*)urls{
    NSMutableDictionary * stoneobs_net_param_dic = [NSMutableDictionary new];
    NSString * stoneobs_net_user_id = [STTools_UserManger defult].stoneobs_fun_get_loginedUser.uid.description;
    NSString * stoneobs_net_user_token = STTools_UserManger.defult.stoneobs_fun_get_loginedUser.token;
    if (stoneobs_net_user_id.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_id forKey:@"uid"];
    }
    if (stoneobs_net_user_token.length) {
        [stoneobs_net_param_dic setObject:stoneobs_net_user_token forKey:@"token"];
    }

    
    if (!self.icon_url.length) {
        [SVProgressHUD showInfoWithStatus:@"请选择头像"];
        return;
    }
    [stoneobs_net_param_dic setObject:self.icon_url forKey:@"header_img"];
    if (!self.nameTextFiled.text.length) {
        [SVProgressHUD showInfoWithStatus:@"请输入姓名"];
        return;
    }
    [stoneobs_net_param_dic setObject:self.nameTextFiled.text forKey:@"real_name"];
    
    for (STTools_TableEasyModel * model in self.dataSouce.stoneobs_fun_dissolveArray) {
        if (model.accessoryView) {
            UITextField * textFiled = (id)model.accessoryView;
            if (!textFiled.text.length) {
                [SVProgressHUD showErrorWithStatus:textFiled.placeholder];
                return;
            }
        }
    }
    [stoneobs_net_param_dic setObject:self.sex forKey:@"sex"];
    
    ({
        STTools_TableEasyModel * model = [self modelFormText:@"年龄"];
        UITextField * textFiled = (id)model.accessoryView;
        [stoneobs_net_param_dic setObject:textFiled.text forKey:@"age"];
    });
    
    ({
        STTools_TableEasyModel * model = [self modelFormText:@"职业年龄"];
        UITextField * textFiled = (id)model.accessoryView;
        [stoneobs_net_param_dic setObject:textFiled.text forKey:@"job_age"];
    });
    
    ({
        STTools_TableEasyModel * model = [self modelFormText:@"身份证号"];
        UITextField * textFiled = (id)model.accessoryView;
        [stoneobs_net_param_dic setObject:textFiled.text forKey:@"card"];
    });
    

    
    if (!self.service_area.length) {
        [SVProgressHUD showInfoWithStatus:@"请选择服务区域"];
        return;
    }
    [stoneobs_net_param_dic setObject:self.service_area forKey:@"service_area"];
    
    
    
    NSMutableArray * major_ids = NSMutableArray.new;
    NSMutableArray * price_s= NSMutableArray.new;
    for (STButton * button in self.buttonArray) {
        if (button.selected) {
            [major_ids addObject:button.obj_id];
            if (button.textFiled.text.length) {
                [price_s addObject:button.textFiled.text];
            }else{
                [SVProgressHUD showErrorWithStatus:[NSString stringWithFormat:@"请输入专业的价格"]];
                return;;
            }
            
        }
    }
    if (!major_ids.count) {
        [SVProgressHUD showInfoWithStatus:@"请选择擅长专业"];
        return;
    }
    [stoneobs_net_param_dic setObject:[major_ids componentsJoinedByString:@","] forKey:@"majors"];
    [stoneobs_net_param_dic setObject:[price_s componentsJoinedByString:@","] forKey:@"prices"];
    if (!self.text_view.text.length) {
        [SVProgressHUD showInfoWithStatus:@"请输入个人简介"];
        return;
    }
    [stoneobs_net_param_dic setObject:self.text_view.text forKey:@"brief"];
    [stoneobs_net_param_dic setObject:urls forKey:@"imgs"];
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSString * stoneobs_net_net_url = [NSString stringWithFormat:@"%@%@",RELEASE_SERVER_URL_HEADER,@"v1/nursery/apply"];
    DDLogInfo(@"url:%@",stoneobs_net_net_url);
    DDLogInfo(@"param:%@",stoneobs_net_param_dic);
    [[STTools_NetWrokManger defaultClient] stoneobs_fun_requestWithPath:stoneobs_net_net_url
                                                                 method:STHttpRequestType_stoneobs_enumPost
                                                             parameters:stoneobs_net_param_dic
                                                                success:^(NSURLSessionDataTask *operation, id responseObject) {
        [SVProgressHUD dismiss];
        NSDictionary * stoneobs_net_model_dic = [responseObject valueForKey:@"data"];
        [SVProgressHUD showSuccessWithStatus:@"提交成功,请等待审核"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.navigationController popToRootViewControllerAnimated:YES];
        });
        // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
        DDLogInfo(@"%@请求成功:resp\n%@",stoneobs_net_net_url,responseObject);
        
        
    } failure:^(NSString *stateCode, STTools_Error *error,NSError *originError) {
        [SVProgressHUD dismiss];
        [SVProgressHUD showErrorWithStatus:error.desc];
        DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                   stoneobs_net_net_url,stoneobs_net_param_dic,error.desc,error.code);
    }];
}
@end
